TreeNode

The TreeNode class represents a node in a tree structure.

Note: The TreeNode class is used extensively in the World module to build hierarchical tree structures. Users can instantiate TreeNode objects and customize them by inheriting from the class to add additional attributes or methods tailored to specific applications.

TreeNode class encapsulates the following attributes:

id (int or str)

Unique identifier for the node.

val (any, optional)

Value associated with the node. Defaults to the label if not provided.

children (list of TreeNode objects)

List of child nodes.

edges (list of int or float, optional)

List of edge weights corresponding to each child node. Defaults to a list of 1s if not provided and children are present.

isGoalState (bool)

Indicates if the node is a goal state.

_heatMapValue (int)

Internal attribute used for heat map visualization (default is 0).

Methods

__init__(self, label, children: list, val=None, isGoalState: bool = False, edges: list = [])

Initializes a TreeNode instance.

Parameters

  • label (int or str): Unique identifier for the node.
  • children (list of TreeNode objects): List of child nodes.
  • val (any, optional): Value associated with the node. Defaults to label if not provided.
  • isGoalState (bool, optional): Indicates if the node is a goal state. Defaults to False.
  • edges (list of int or float, optional): List of edge weights corresponding to each child node. Defaults to an empty list.

__str__(self) -> str

Returns a string representation of the TreeNode object.

Parameters

  • None

Returns

  • str: String representation of the TreeNode object.